package com.khyr.Service.impl;

import com.khyr.Dao.CareOrderItemDao;
import com.khyr.Dao.HisOrderChargeItemDao;
import com.khyr.Service.DispenseMedicineService;
import com.khyr.entity.CareOrderItem;
import com.khyr.entity.HisOrderChargeItem;
import com.khyr.feign.MedicinesFeign;
import com.khyr.vo.R;
import com.khyr.vo.dispenseMedicineVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：lyk
 * @date ：Created in 2025/3/14 15:19
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class DispenseMedicineServiceImpl implements DispenseMedicineService {
    @Autowired
    private HisOrderChargeItemDao hisOrderChargeItemDao;
    @Autowired
    private CareOrderItemDao careOrderItemDao;
    @Autowired
    private MedicinesFeign medicinesFeign;
    @Override
    public R<String> doMedicine(List<String> items) {
        List<dispenseMedicineVo> dispenseMedicineVos = new ArrayList<>();
        for (String item : items) {
            HisOrderChargeItem hisOrderChargeItem = hisOrderChargeItemDao.selectById(item);
            dispenseMedicineVos.add(new dispenseMedicineVo(hisOrderChargeItem.getItemNum(),hisOrderChargeItem.getItemName()));
            hisOrderChargeItem.setStatus("3");
            hisOrderChargeItemDao.updateById(hisOrderChargeItem);
            CareOrderItem careOrderItem = careOrderItemDao.selectById(item);
            careOrderItem.setStatus("3");
            careOrderItemDao.updateById(careOrderItem);
            medicinesFeign.reduce(hisOrderChargeItem.getItemName(),hisOrderChargeItem.getItemNum());
        }
        if (!dispenseMedicineVos.isEmpty()){
        return new R<>(200,"操作成功",null);
    }else{
            return new R<>(500,"操作失败",null);
        }
    }

}
